﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace CustSign
{
    public partial class frmCustDataUp : Form
    {
        OleDbConnection Conn;
        

        public frmCustDataUp()
        {
            InitializeComponent();
        }

        private void frmCustDataUp_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dSCustData.CustList”中。您可以根据需要移动或移除它。
            this.custListTableAdapter.Fill(this.dSCustData.CustList);

            Conn = new OleDbConnection();
            Conn.ConnectionString = Properties.Settings.Default.strConn;

            OleDbCommand Comm = Conn.CreateCommand();
            Comm.CommandText = "SELECT ID, FieldName, HeadName, FieldType, ColWidth, ColMinWidth, ColType FROM TCols ORDER BY ID";

            Conn.Open();
            OleDbDataReader dgvColSetReader;

            dgvColSetReader = Comm.ExecuteReader();
            DataGridViewCheckBoxColumn NewSelCol = new DataGridViewCheckBoxColumn();
            NewSelCol.HeaderText = "选中";
            NewSelCol.Width = 70;
            NewSelCol.ReadOnly = false;
            dgvCustList.Columns.Add(NewSelCol);

            while (dgvColSetReader.Read())
            {            
                DataGridViewTextBoxColumn NewtxtCol = new DataGridViewTextBoxColumn();
                NewtxtCol.DataPropertyName = (String)dgvColSetReader["FieldName"];
                NewtxtCol.HeaderText = (String)dgvColSetReader["HeadName"];
                NewtxtCol.Width = (Int32)dgvColSetReader["ColWidth"];
                NewtxtCol.MinimumWidth = (Int32)dgvColSetReader["ColMinWidth"];
                //NewtxtCol.ReadOnly = true;
                dgvCustList.Columns.Add(NewtxtCol);
            }
            dgvCustList.DataSource = this.custListBindingSource;

            Comm.Dispose();
            dgvColSetReader.Close();
            dgvColSetReader.Dispose();
            Conn.Close();
            Conn.Dispose();
        }

        private void btCustAdd_Click(object sender, EventArgs e)
        {
            custListBindingSource.AddNew();
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            custListBindingSource.EndEdit();
            this.custListTableAdapter.Update(this.dSCustData.CustList);
            this.custListTableAdapter.Fill(this.dSCustData.CustList);
        }

        private void btCustDel_Click(object sender, EventArgs e)
        {
            custListBindingSource.RemoveCurrent();            
            this.custListTableAdapter.Update(this.dSCustData.CustList);
            this.custListTableAdapter.Fill(this.dSCustData.CustList);
            
        }
    }
}
